﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SOA.cs" company="Rolosoft Ltd">
//   © Rolosoft Ltd
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

#region License

// Copyright 2013 Rolosoft Ltd
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#endregion

namespace Rsft.Net.Dns.Entities.Records
{
    #region Usings

    using System.Diagnostics.Contracts;
    using System.Globalization;

    using Rsft.Net.Dns.Interfaces;

    #endregion

    /// <summary>
    ///     The SOA record.
    /// </summary>
    public sealed class SOA : Record
    {
        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="SOA"/> class.
        /// </summary>
        /// <param name="recordReader">
        /// The record reader.
        /// </param>
        public SOA(IRecordReader recordReader)
            : base(recordReader)
        {
            Contract.Requires(recordReader != null);

            this.Mname = recordReader.ReadDomainName();
            this.Rname = recordReader.ReadDomainName();
            this.Serial = recordReader.ReadUInt32();
            this.Refresh = recordReader.ReadUInt32();
            this.Retry = recordReader.ReadUInt32();
            this.Expire = recordReader.ReadUInt32();
            this.Minimum = recordReader.ReadUInt32();
        }

        /// <summary>
        ///     Initializes a new instance of the <see cref="SOA" /> class.
        /// </summary>
        public SOA()
        {
        }

        #endregion

        #region Public Properties

        /// <summary>
        ///     Gets Expire.
        /// </summary>
        public uint Expire { get; private set; }

        /// <summary>
        ///     Gets Minimum.
        /// </summary>
        public uint Minimum { get; private set; }

        /// <summary>
        ///     Gets Mname.
        /// </summary>
        public string Mname { get; private set; }

        /// <summary>
        ///     Gets Refresh.
        /// </summary>
        public uint Refresh { get; private set; }

        /// <summary>
        ///     Gets Retry.
        /// </summary>
        public uint Retry { get; private set; }

        /// <summary>
        ///     Gets Rname.
        /// </summary>
        public string Rname { get; private set; }

        /// <summary>
        ///     Gets Serial.
        /// </summary>
        public uint Serial { get; private set; }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        ///     Returns a <see cref="System.String" /> that represents this instance.
        /// </summary>
        /// <returns>
        ///     A <see cref="System.String" /> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            return string.Format(
                CultureInfo.InvariantCulture, 
                "{0} {1} {2} {3} {4} {5} {6}", 
                this.Mname, 
                this.Rname, 
                this.Serial, 
                this.Refresh, 
                this.Retry, 
                this.Expire, 
                this.Minimum);
        }

        #endregion
    }
}